home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / hoobie / promisc.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-11-06  |  2.7 KB  |  97 lines

  1.  
  2. This will scan your devices to detect sniffers on your system.
  3. Linux support is ready but SunOS has some problems (mainly in
  4. net/if.h when i tried compiling i got a lot of parse errors in
  5. if.h and socket.h <shrug> maybe the system i was on was damaged.)
  6.  
  7. Comments welcome :-).
  8.  
  9. begin promisc.c --
  10. // $Id: promisc.c,v null 1997/03/09 10:35:58 trevorl Exp $
  11. // promisc.c: test devices for sniffers and device moniters.
  12. //
  13. // Copyright (C) 1997 Trevor F. Linton (blind@xmission.com)
  14. //
  15. // Created for Linux based loosely upon linux ioctl controls.
  16. // ioctl() is used to detect different flags set on devices used
  17. // on your system.
  18. //
  19. // gcc -o sys_test promisc.c
  20. //
  21.  
  22. #include <stdio.h>
  23. #include <sys/socket.h>
  24. #include <sys/ioctl.h>
  25. #include <errno.h>
  26. #if defined (__linux__)
  27. #include <linux/if.h>
  28. #else
  29. #include <net/if.h>
  30. #endif
  31. #define size(p) (sizeof(p))
  32.  
  33. int dev_flags=0,
  34.     device_flags=0,
  35.     set_look_all=0;
  36.  
  37. int
  38. main(int argc, char **argv) {
  39.  struct ifreq ifreq, *ifr;
  40.  struct ifconf ifc;
  41.  char buf[BUFSIZ], *cp, *cplim;
  42.  
  43.  if(argc <= 1)
  44.         set_look_all++;
  45.  
  46.  if((dev_flags = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
  47.         fprintf(stderr, "An error occured establiashing while establishing a socket\n");
  48.         perror("socket");
  49.         exit(1);
  50.  }
  51.  
  52.  ifc.ifc_len = sizeof(buf);
  53.  ifc.ifc_buf = buf;
  54.  
  55.  if(ioctl(dev_flags, SIOCGIFCONF, (char *)&ifc) < 0) {
  56.         perror("SIOCGIFCONF");
  57.         exit(1);
  58.  }
  59.  ifr = ifc.ifc_req;
  60.  cplim=buf+ifc.ifc_len;
  61.  for(cp = buf; cp < cplim;
  62.                 cp += sizeof (ifr->ifr_name) + size(ifr->ifr_addr))
  63.  {
  64.                 ifr = (struct ifreq *)cp;
  65.  
  66.                 if(argv[1])
  67.                         if(strcmp(ifr->ifr_name, argv[1]) && !set_look_all)
  68.                                 continue;
  69.  
  70.                 ifreq = *ifr;
  71.                 if(ioctl(dev_flags, SIOCGIFFLAGS, (char *)&ifreq) < 0)
  72.                 {
  73.                         fprintf(stderr, "SIOCGIFFLAGS: %s (get interface flags): %s\n", ifr->ifr_name,strerror(errno));
  74.                         continue;
  75.                 }
  76.  
  77.                 device_flags=0; device_flags = ifreq.ifr_flags;
  78.                 fprintf(stdout, "%s: ", ifreq.ifr_name);
  79.  
  80.                 if((device_flags & IFF_PROMISC) != 0)
  81.                         fprintf(stdout, "Promiscuous: Sniffer detected.\n");
  82.                 else
  83.                         fprintf(stdout, "Not-Promiscous: No Sniffers detected.\n");
  84.  
  85.                 if(!set_look_all)
  86.                         exit(0); // We're finished..
  87.                 else
  88.                         continue; // Go onto next device..
  89.  
  90.  }
  91.  if(!set_look_all)
  92.          fprintf(stdout, "%s: Unknown device.\n", argv[1]);
  93.                                         // Device not found..
  94. }
  95. end promisc.c --
  96.  
  97.